home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
blankery
/
blanker
/
source
/
blankers
/
aswarm
/
blank.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-15
|
9KB
|
317 lines
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/screens.h>
#include <dos/dos.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/copper.h>
#include <graphics/videocontrol.h>
#include <hardware/custom.h>
#include <hardware/dmabits.h>
#include <graphics/gfxmacros.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/alib_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/utility_protos.h>
#include <clib/alib_protos.h>
#include <stdlib.h>
#include "ASwarm.h"
#include "/defs.h"
#include "/utility.h"
#define MAX_SPEED 6L
#define MAX_WASPS 10L
#define MAX_BEES 500L
#define MAX_TIGHTNESS 10L
#define BEEACC 3
#define BEEVEL 17
#define WASPACC 5
#define WASPVEL 21
#define BORDER 5
#define BEE_PEN 1
#define WASP_PEN 2
#define BEE_COL_NUM 33
#define RAND( m ) ( RangeRand( m ) - ( m ) / 2 )
#define BXVel( I ) ( SP->ss_X[3][I] )
#define BYVel( I ) ( SP->ss_Y[3][I] )
#define BeeX( P, I ) ( SP->ss_X[P][I] )
#define BeeY( P, I ) ( SP->ss_Y[P][I] )
#define MyWasp( I ) ( SP->ss_MW[I] )
#define WaXVel( I ) ( SP->ss_WX[3][I] )
#define WaYVel( I ) ( SP->ss_WY[3][I] )
#define WaspX( P, I ) ( SP->ss_WX[P][I] )
#define WaspY( P, I ) ( SP->ss_WY[P][I] )
struct mPrefObject {
LONG Wasps, Bees, Tightness, Speed, Colorcycling, Aimmode;
};
struct SwarmStruct {
WORD ss_Width;
WORD ss_Height;
WORD ss_NumWasps;
WORD *ss_WX[4];
WORD *ss_WY[4];
WORD *ss_NB;
WORD ss_NumBees;
WORD ss_BeeAcc;
WORD *ss_X[4];
WORD *ss_Y[4];
WORD *ss_MW;
};
extern struct mPrefObject nP;
extern ULONG Depth, Mode;
extern UBYTE *prefData;
UWORD BeeColors[BEE_COL_NUM] = {
0x000F, 0x000F, 0x004F, 0x008F, 0x00BF, 0x00FF, 0x00FB, 0x00F7, 0x00F3, 0x00F0, 0x04F0, 0x08F0, 0x09F0,
0x0AF0, 0x0BF0, 0x0CF0, 0x0DF0, 0x0EF0, 0x0FF0, 0x0FE0, 0x0FD0, 0x0FC0, 0x0FB0, 0x0F90, 0x0F80, 0x0F70,
0x0F60, 0x0F50, 0x0F40, 0x0F30, 0x0F20, 0x0F10, 0x0F00
};
UWORD SwarmColors[4] = {
0x0000, 0x0000, 0x0FFF, 0x0000
};
BYTE sqrt_tab[256] = {
0,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,14,
14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,15,15
};
LONG FastSQRT( LONG x )
{
LONG sr = 1L;
while( x > 255L ) {
x /= 4L;
sr *= 2L;
}
return( sr * (LONG)sqrt_tab[x] );
}
ULONG SwarmSize( LONG NumWaps, LONG NumBees )
{
return sizeof( struct SwarmStruct ) + sizeof( WORD ) * ( (ULONG)NumWaps * 9L + (ULONG)NumBees * 9L );
}
struct SwarmStruct *CreateSwarms( struct Screen *Scr, LONG NumWasps, LONG NumBees, LONG Speed, LONG Tightness )
{
LONG Index;
struct SwarmStruct *SP;
WORD *Ptr;
if(( SP = AllocVec( SwarmSize( NumWasps, NumBees ), 0L )) == NULL) return NULL;
SP->ss_NumWasps = NumWasps;
SP->ss_NumBees = NumBees;
SP->ss_Width = Scr->Width;
SP->ss_Height = Scr->Height;
SP->ss_BeeAcc = ( Tightness * BEEACC )/MAX_SPEED+1;
Ptr = (WORD *)( &SP[1] );
for( Index = 0L; Index < 4L; Index++ ) {
SP->ss_WX[Index] = Ptr;
Ptr += NumWasps;
SP->ss_WY[Index] = Ptr;
Ptr += NumWasps;
SP->ss_X[Index] = Ptr;
Ptr += NumBees;
SP->ss_Y[Index] = Ptr;
Ptr += NumBees;
}
SP->ss_NB = Ptr;
SP->ss_MW = Ptr + NumWasps;
for( Index = 0L; Index < NumWasps; Index++ ) {
WaspX( 1, Index ) = WaspX( 0, Index ) = BORDER + RangeRand( SP->ss_Width - 2 * BORDER );
WaspY( 1, Index ) = WaspY( 0, Index ) = BORDER + RangeRand( SP->ss_Height - 2 * BORDER );
WaXVel( Index ) = RAND( WASPACC );
WaYVel( Index ) = RAND( WASPACC );
SP->ss_NB[Index]=0;
}
for( Index = 0L; Index < SP->ss_NumBees; Index++ ) {
BeeX( 1, Index ) = BeeX( 0, Index ) = BORDER + RangeRand( SP->ss_Width - 2 * BORDER );
BeeY( 1, Index ) = BeeY( 0, Index ) = BORDER + RangeRand( SP->ss_Height - 2 * BORDER );
BXVel( Index ) = RAND( SP->ss_BeeAcc );
BYVel( Index ) = RAND( SP->ss_BeeAcc );
SP->ss_NB[MyWasp( Index ) = Index % SP->ss_NumWasps]++;
}
return SP;
}
VOID DrawSwarms( struct RastPort *RP, struct SwarmStruct *SP, LONG AimMode )
{
LONG Index;
for( Index = 0L; Index < SP->ss_NumWasps; Index++ ) {
WaspX( 2, Index ) = WaspX( 1, Index );
WaspX( 1, Index ) = WaspX( 0, Index );
WaspY( 2, Index ) = WaspY( 1, Index );
WaspY( 1, Index ) = WaspY( 0, Index );
WaXVel( Index ) += RAND( WASPACC );
WaYVel( Index ) += RAND( WASPACC );
if( WaXVel( Index ) > WASPVEL ) WaXVel( Index ) = WASPVEL;
if( WaXVel( Index ) < -WASPVEL ) WaXVel( Index ) = -WASPVEL;
if( WaYVel( Index ) > WASPVEL ) WaYVel( Index ) = WASPVEL;
if( WaYVel( Index ) < -WASPVEL ) WaYVel( Index ) = -WASPVEL;
WaspX( 0, Index ) = WaspX( 1, Index ) + WaXVel( Index );
WaspY( 0, Index ) = WaspY( 1, Index ) + WaYVel( Index );
if(( WaspX( 0, Index ) < BORDER )||( WaspX( 0, Index ) > SP->ss_Width-BORDER-1 )) {
WaXVel( Index ) = -WaXVel( Index );
if( WaspX( 0, Index ) < BORDER ) WaspX( 0, Index ) = BORDER;
else WaspX( 0, Index ) = SP->ss_Width-BORDER-1;
}
if(( WaspY( 0, Index ) < BORDER )||( WaspY( 0, Index ) > SP->ss_Height-BORDER-1 )) {
WaYVel( Index ) = -WaYVel( Index );
if( WaspY( 0, Index ) < BORDER ) WaspY( 0, Index ) = BORDER;
else WaspY(0, Index ) = SP->ss_Height-BORDER-1;
}
}
for( Index = 0L; Index < SP->ss_NumBees; Index++ ) {
WORD DX, DY, ChkIndex;
LONG Distance, NewDistance;
BeeX( 2, Index ) = BeeX( 1, Index );
BeeX( 1, Index ) = BeeX( 0, Index );
BeeY( 2, Index ) = BeeY( 1, Index );
BeeY( 1, Index ) = BeeY( 0, Index );
DX = WaspX( 1, MyWasp( Index )) - BeeX( 1, Index );
DY = WaspY( 1, MyWasp( Index )) - BeeY( 1, Index );
Distance = FastSQRT( DX * DX + DY * DY );
if( !Distance ) Distance = 1L;
if( AimMode ) {
for( ChkIndex = 0; ChkIndex <= SP->ss_NumWasps; ChkIndex++ ) {
if( ChkIndex != MyWasp( Index )) {
LONG NewDX, NewDY;
NewDX = WaspX( 1, ChkIndex ) - BeeX( 1, Index );
NewDY = WaspY( 1, ChkIndex ) - BeeY( 1, Index );
NewDistance = FastSQRT( NewDX * NewDX + NewDY * NewDY );
if( Distance > NewDistance ) {
DX = NewDX;
DY = NewDY;
if(!( NewDistance )) Distance = 1L;
else Distance = NewDistance;
SP->ss_NB[MyWasp( Index )]--;
SP->ss_NB[MyWasp( Index ) = ChkIndex]++;
}
}
}
}
BXVel( Index ) +=( DX * SP->ss_BeeAcc ) / Distance + RAND( 3 );
BYVel( Index ) +=( DY * SP->ss_BeeAcc ) / Distance + RAND( 3 );
if( BXVel( Index ) > BEEVEL ) BXVel( Index ) = BEEVEL;
if( BXVel( Index ) < -BEEVEL ) BXVel( Index ) = -BEEVEL;
if( BYVel( Index ) > BEEVEL ) BYVel( Index ) = BEEVEL;
if( BYVel( Index ) < -BEEVEL ) BYVel( Index ) = -BEEVEL;
BeeX( 0, Index ) = BeeX( 1, Index ) + BXVel( Index );
BeeY( 0, Index ) = BeeY( 1, Index ) + BYVel( Index );
if(( BeeX( 0, Index ) < BORDER )||( BeeX( 0, Index ) > SP->ss_Width-BORDER-1 )) {
BXVel( Index ) = -BXVel( Index );
BeeX( 0, Index ) = BeeX( 1, Index ) + BXVel( Index );
}
if(( BeeY( 0, Index ) < BORDER )||( BeeY( 0, Index ) > SP->ss_Height-BORDER-1 )) {
BYVel( Index ) = -BYVel( Index );
BeeY( 0, Index ) = BeeY( 1, Index ) + BYVel( Index );
}
}
for( Index = 0L; Index < SP->ss_NumWasps; Index++ ) {
SetAPen( RP, 0 );
Move( RP, WaspX( 2, Index ), WaspY( 2, Index ));
Draw( RP, WaspX( 1, Index ), WaspY( 1, Index ));
SetAPen( RP, WASP_PEN );
Draw( RP, WaspX( 0, Index ), WaspY( 0, Index ));
}
for( Index = 0L; Index < SP->ss_NumBees; Index++ ) {
SetAPen( RP, 0 );
Move( RP, BeeX( 2, Index ), BeeY( 2, Index ));
Draw( RP, BeeX( 1, Index ), BeeY( 1, Index ));
SetAPen( RP, BEE_PEN );
Draw( RP, BeeX( 0, Index ), BeeY( 0, Index ));
}
}
VOID blank( VOID )
{
struct Screen *SwarmScreen;
struct SwarmStruct *Swarms;
struct mPrefObject *mP;
LONG Count;
WORD Color, DColor;
if( ASwarmWnd ) mP = &nP;
else mP = ( struct mPrefObject * )prefData;
SwarmScreen = OpenScreenTags( NULL, SA_Depth, 2, SA_Overscan, OSCAN_STANDARD, SA_DisplayID, Mode, SA_Quiet,
TRUE, SA_Behind, TRUE, TAG_DONE );
if( SwarmScreen ) {
SetRGB4( &( SwarmScreen->ViewPort ), 0, 0, 0, 0 );
SetRast( &( SwarmScreen->RastPort ), 0 );
BlankMousePointer();
ScreenToFront( SwarmScreen );
if( Swarms = CreateSwarms( SwarmScreen, mP->Wasps, mP->Bees, mP->Speed + 1, mP->Tightness )) {
Color = BEE_COL_NUM-1;
DColor = mP->Colorcycling ? 1 : 0;
Count = mP->Speed + 1;
while(!( SetSignal( 0, 0 )& SIGBREAKF_CTRL_C )){
SwarmColors[BEE_PEN] = BeeColors[Color];
LoadRGB4( &( SwarmScreen->ViewPort ), SwarmColors, 4 );
Color += DColor;
if(( Color == -1 )||( Color == BEE_COL_NUM )) {
DColor = -DColor;
Color += 2 * DColor;
}
WaitTOF();
if( ++Count > MAX_SPEED ) {
Count = mP->Speed + 1;
DrawSwarms( &( SwarmScreen->RastPort ), Swarms, mP->Aimmode );
}
}
SetSignal( 0L, SIGBREAKF_CTRL_C );
FreeVec( (APTR)Swarms );
}
UnblankMousePointer();
CloseScreen( SwarmScreen );
}
}